#region Using directives
using System;
using System.Text;
using System.Data;
using System.Collections;
using WP.MF.DataEntity;
using WP.MF.DataAccess;
using WP.MF.BusinessRule;
using WP.DB;
using WP.Commons;
#endregion

namespace WP.MF.BusinessLogical 
{
    public class MMiscSwitchBLL : IBusinessLogical
    {
        MMiscSwitchDAL mMiscSwitchDAL = new MMiscSwitchDAL();

        public MMiscSwitchBLL()
		{
		}

        #region ***For implement interface

        #region Select Record by RECID OverLoad +1
        public MMiscSwitchDEL SelectDataByRecID(DBAccess dBAccess, string strRecId)
        {
            MMiscSwitchDEL mMiscSwitchDEL = new MMiscSwitchDEL();

            DataFunctions.SelectByRecID(dBAccess, mMiscSwitchDEL, mMiscSwitchDAL.Fields, strRecId);

            return mMiscSwitchDEL;
        }

        public IDataEntity SelectDataByRecID(string strRecId)
        {
            DBAccess dBAccess = new DBAccess(false, false);
            try
            {
                MMiscSwitchDEL mMiscSwitchDEL = SelectDataByRecID(dBAccess, strRecId);
                return mMiscSwitchDEL as IDataEntity;
            }
            catch (Exception e)
            {
                ExceptionManager.ProcessException(e);
                return null;
            }
            finally
            {
                dBAccess.CloseCon();
            }
        }
        #endregion

        #region Insert MMiscSwitch
        public bool Insert(DBAccess dBAccess, MMiscSwitchDEL mMiscSwitchDEL)
        {
            bool bFlag = true;
            MMiscSwitchBRL mMiscSwitchBRL = new MMiscSwitchBRL();

            //BaseFunctions.SpecialCharDeal(mMiscSwitchDEL);

            if (mMiscSwitchBRL.InsertValid(dBAccess, mMiscSwitchDEL))
            {
                mMiscSwitchDAL.InsertMMiscSwitch(dBAccess, mMiscSwitchDEL);
            }
            else
            {
                bFlag = false;
            }
            return bFlag;

        }

        public bool Insert(IDataEntity iMMiscSwitchDEL)
        {
            bool bReturn = true;
            DBAccess dBAccess = null;
            MMiscSwitchDEL mMiscSwitchDEL = iMMiscSwitchDEL as MMiscSwitchDEL;
            dBAccess = new DBAccess(false, true);

            try
            {
                bReturn = Insert(dBAccess, mMiscSwitchDEL);
                if (bReturn)
                {
                    dBAccess.CommitTranAndCloseCon();
                }
                else
                {
                    dBAccess.RollbackTranAndClose();
                    if (SysVar.ErrorMessage.Count > 0)
                    {
                        MsgBoxEx.Show(SysVar.ErrorMessage, SysVar.WarnTitle);
                    }
                }
            }
            catch (Exception e)
            {
                dBAccess.RollbackTran();
                bReturn = false;
                ExceptionManager.ProcessException(e);
            }

            return bReturn;
        }
        #endregion

        #region Update MMiscSwitch
        public bool Update(DBAccess dBAccess, MMiscSwitchDEL mMiscSwitchDEL)
        {
            bool bFlag = true;
            MMiscSwitchBRL mMiscSwitchBRL = new MMiscSwitchBRL();

            //BaseFunctions.SpecialCharDeal(mMiscSwitchDEL);

            if (mMiscSwitchBRL.UpdateValid(dBAccess, mMiscSwitchDEL))
            {
                mMiscSwitchDAL.UpdateMMiscSwitch(dBAccess, mMiscSwitchDEL);
            }
            else
            {
                bFlag = false;
            }
            return bFlag;
        }

        public bool Update(IDataEntity iMMiscSwitchDEL)
        {
            bool bReturn = true;
            MMiscSwitchDEL mMiscSwitchDEL = iMMiscSwitchDEL as MMiscSwitchDEL;
            DBAccess dBAccess = new DBAccess(false, true);

            try
            {
                bReturn = Update(dBAccess, mMiscSwitchDEL);
                if (bReturn)
                {
                    dBAccess.CommitTranAndCloseCon();
                }
                else
                {
                    dBAccess.RollbackTranAndClose();
                    if (SysVar.ErrorMessage.Count > 0)
                    {
                        MsgBoxEx.Show(SysVar.ErrorMessage, SysVar.WarnTitle);
                    }
                }
            }
            catch (Exception e)
            {
                dBAccess.RollbackTran();
                ExceptionManager.ProcessException(e);
                bReturn = false;
            }

            return bReturn;
        }
        #endregion

        #region Delete MMiscSwitch
        public bool Delete(string strRecId, byte[] btOldRecStamp)
        {
            MMiscSwitchBRL mMiscSwitchBRL = new MMiscSwitchBRL();
            DBAccess dBAccess = new DBAccess(false, true);

            try
            {
                if (mMiscSwitchBRL.DeleteValid(dBAccess, strRecId, btOldRecStamp))
                {
                    mMiscSwitchDAL.DeleteMMiscSwitch(dBAccess, int.Parse(strRecId));
                    dBAccess.CommitTranAndCloseCon();

                    return true;
                }
                else
                {
                    dBAccess.RollbackTranAndClose();
                    if (SysVar.ErrorMessage.Count > 0)
                    {
                        MsgBoxEx.Show(SysVar.ErrorMessage, SysVar.WarnTitle);
                    }
                    return false;
                }
            }
            catch (Exception e)
            {
                dBAccess.RollbackTranAndClose();
                ExceptionManager.ProcessException(e);
                return false;
            }
        }

        #endregion

        #endregion***
    }
}
